/*
 * @Author: zgx 2324461523@qq.com
 * @Date: 2024-02-26 15:11:25
 * @LastEditors: zgx 2324461523@qq.com
 * @LastEditTime: 2024-02-26 16:50:33
 * @FilePath: \tph_shop\src\api\address.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { http } from '@/utils/http'
import type { addressInfoType } from '@/types/address'

enum API {
  GETADDRESSAPI = '/member/address',
}

// 获取地址列表
export const getAddressListAPI = () => {
  return http<addressInfoType[]>({
    url: API.GETADDRESSAPI,
    method: 'GET',
  })
}

// 新增|修改收货地址
export const postAddAddressAPI = (data: addressInfoType) => {
  if (data.id) {
    // 存在，是修改
    return http({
      method: 'PUT',
      url: `${API.GETADDRESSAPI}/${data.id}`,
      data,
    })
  } else {
    return http<{ id: string }>({
      method: 'POST',
      url: API.GETADDRESSAPI,
      data,
    })
  }
}

// 获取地址详情的接口
export const getAddressDetailAPI = (id: string) => {
  return http<addressInfoType>({
    method: 'GET',
    url: `${API.GETADDRESSAPI}/${id}`,
  })
}

// 删除收货地址的接口
export const deleteAddressAPI = (id: string) => {
  return http<{ id: string }>({
    method: 'DELETE',
    url: `${API.GETADDRESSAPI}/${id}`,
  })
}